package com.bharatonjava.stump.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.bharatonjava.stump.domain.Employee;

public class EmployeeDaoImpl implements EmployeeDao{

	@Autowired
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public EmployeeDaoImpl() {
	}
	
	@Override
	public Long saveEmployee(Employee employee) {
		Session session = sessionFactory.getCurrentSession();
		Long employeeId = (Long) session.save(employee);
		return employeeId;
	}

	@Override
	public Long updateEmployee(Employee employee) {
		Session session = sessionFactory.getCurrentSession();
		session.update(employee);
		return null;
	}

	@Override
	public Long deleteEmployee(Employee employee) {
		
		return null;
	}

	@Override
	public Employee getEmployeeById(Long employeeId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Employee> getEmployees() {
		Session session = sessionFactory.getCurrentSession();
		List<Employee> emps = (List<Employee>) session.createQuery("from Employee e").list();
		return emps;
	}

}
